const app = getApp()
Page({
  data: {
    isRead: true,
    nav_on_5:'on',
    close_jiayi: true,
    isShow: false,
    isUser:false
    // gender: 'on'
  },
  onLoad: function (options) {
    var that = this;
    app.updateFlag(this).then(res => {
      if (!app.isAuth) {
        that.setData({
          isUser: app.isAuth
        })
      } else {
        that.setData({
          isUser: app.isAuth
        })
        app.userstat(that, wx.getStorageSync("openid"))
        that.getMedal()
      }
    })
		//徽章列表
    console.log(wx.getStorageSync('close_tip_s'))
    if (wx.getStorageSync('close_tip_s') === '') {
      wx.setStorageSync('close_tip_s', true)
    }
    console.log(wx.getStorageSync('close_tip_s'))
    that.setData({
      close_tip: wx.getStorageSync('close_tip_s')
    })
		// app.request(app.apiDomain + "index.php?c=user&a=medal", {}, function(res) {
		// 	//循环查询id
		// 	var BadgeData = [];
		// 	var data = res.data.data.data;
		// 	for(var i=0;i < data.length;i++){
		// 		for(var r=0; r < data[i].list.length;r++){
		// 			if(data[i].list[r].is_show == 'on' || data[i].list[r].show == 'on'){
		// 				BadgeData.unshift(data[i].list[r])
		// 			}else{
		// 				BadgeData.push(data[i].list[r])
		// 			}
		// 		}
		// 	};
		// 	that.setData({
		// 		BadgeData:BadgeData,
		// 		z_num:res.data.data.sum,
		// 		z_total:res.data.data.total
		// 	})
		// 	// console.log(BadgeData)
		// });	
		//
        that.setData({
          isGet: wx.getStorageSync('isGetChicken')
        })
        // app.userstat(this,)
        // 请求有没有新信息
		// app.request(app.apiDomain+"index.php?c=message&a=isRead",{},res=>{
    //         // console.log(111);
		// 	console.log(res);
		// 	if(res.data.data==1){
		// 		//有未读消息
		// 		that.setData({
		// 			isRead: false
		// 		})
		// 	}else if(res.data.data==0){
		// 		// 没有未读消息
		// 		that.setData({
		// 			isRead: true
		// 		})
		// 	}
		// })
  },
  close_jiayi() {
    let that = this
    that.setData({
      close_jiayi: false
    })
  },
	off_click:function(){
		wx.showToast({
		  title: '该功能已下架',
		  icon: 'none',
		  duration: 2000
		}) 
	},
  openSet: function () {
    wx.openSetting({
      
    })
  },
  close_tip: function () {
    wx.setStorageSync('close_tip_s', false)
    this.setData({
      close_tip: wx.getStorageSync('close_tip_s')
    })
    console.log(wx.getStorageSync('close_tip_s'))
  },
  // 点击下载
  downApp(){
      var that = this
    // 判断是安卓还是ios
    console.log(wx.getSystemInfoSync());
    const system = wx.getSystemInfoSync().system;
    if (/android|Android/i.test(system)) {
        // 安卓
        console.log('android');
        wx.navigateTo({
            url: '../personal/downApp'
          })
    } else {
        // ios
        console.log('ios');
        wx.hideToast()
        wx.setClipboardData({
            data: "http://wap.91160.com/index.php?c=scan&a=index&code=dPhS3aD5q4R0%2BFLdoPmrhMG1v.hgq2fGRCOS7wVwqXCgYLhdNDaUnQ%3D%3D",
            success(res) {
                wx.hideToast()
            //   console.log(res.data) // data
                that.setData({
                    gender:'on'
                })
            }
        })
    }
  },
  gender_off:function(){
    this.setData({
        gender:''
    })
},
  onReady: function () {
		// var that = this;
		// if(!app.userInfo.nickname || !app.userInfo.icon){
		//     wx.navigateTo({
		//         url: '../logs/accredit?jump=../personal/index'
		//     })
		// }
		// this.setData({
		//     userInfo: app.userInfo
		// })
// 		app.request(app.apiDomain + 'index.php?c=user&a=userstat',{},res=>{
// 			console.log(res);
// 			if(res.data.status=='1'){
// 				that.setData({
// 					user: res.data.data
// 				});
// 			}
			// else {
			//   wx.navigateTo({
			//     url: '../logs/accredit?jump=../personal/index'
			//   })
			// }
		// })
		
	},
  // 地址
    step_click() {
        wx.chooseAddress({})
    },
    onShareAppMessage: function () {
        return app.onShareAppMessage();
    },
	onReady: function() {
		app.SystemInfo(this)
	},
  linkPage (e) {
    let linkUrl = e.target.dataset.url
    let linkType = e.target.dataset.type
    if (!app.isAuth) {
      this.setData({
        isShow: true
      })
    } else {
      wx.navigateTo({
        url: linkUrl,
      })
    }
  },
  linkto(e) {
    let linkUrl = e.target.dataset.url
    let linkType = e.target.dataset.type
    wx.navigateTo({
      url: linkUrl,
    })
  },
  goAuth () {
    this.setData({
      isShow: true
    })
  },
  authSuccess(e) {
    this.setData({
      isShow: false,
      isUser: app.isAuth
    })
    this.getMedal()
    app.userstat(this, wx.getStorageSync("openid"))
  },
  authFail(e) {
    this.setData({
      isShow: false
    })
  },
  click() {
    this.setData({
      isShow: false
    })
  },
  getMedal () {
    let that = this
    app.request(app.apiDomain + "index.php?c=user&a=medal", {}, function (res) {
      //循环查询id
      var BadgeData = [];
      var data = res.data.data.data;
      for (var i = 0; i < data.length; i++) {
        for (var r = 0; r < data[i].list.length; r++) {
          if (data[i].list[r].is_show == 'on' || data[i].list[r].show == 'on') {
            BadgeData.unshift(data[i].list[r])
          } else {
            BadgeData.push(data[i].list[r])
          }
        }
      };
      that.setData({
        BadgeData: BadgeData,
        z_num: res.data.data.sum,
        z_total: res.data.data.total
      })
      // console.log(BadgeData)
    });
  },
  onShow: function () {
    var that = this
  }
    
})